<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box{
				height: 100px;
				background: red;
			}
		</style>
		<script>
			window.onload=function(){
				//通过id属性获取div元素
				var oDiv=document.getElementById("box");	
				//如果浏览器存在getComputedStyle()方法，则执行if中的语句
				if(window.getComputedStyle){
					var w=getComputedStyle(oDiv,null)["width"];
					var h=getComputedStyle(oDiv,null)["height"];
					console.log("宽："+w+",高："+h);
				}
				//ie8下的方法
				else{
					var iW=oDiv.currentStyle["width"];
					var iH=oDiv.currentStyle["height"];
					console.log("宽："+iW+",高："+iH);
				}				
			}
		</script>
	</head>
	<body>
		<div id="box"></div>
	</body>
</html>
